[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
gmtime() Convert Time from Long Integer to Structure
#include <time.h>
struct tm *gmtime(time);
const time_t *time; Pointer to stored time
gmtime() converts a time, stored as a long value, to a structure. The
long value 'time' represents the number of seconds that have elapsed
since 00:00:00, Jan 1 1970. (This value can be obtained from a call
to time()). The structure result reflects Greenwich mean time, not
local time.
The structure is of type 'tm', as defined in <time.h>. The fields of
structure 'tm' store the following values:
'tm_sec' Seconds (0-59)
'tm_min' Minutes (0-59)
'tm_hour' Hours (0-23)
'tm_mday' Day of month (1-31)
'tm_mon' Month (0-11; Jan = 0)
'tm_year' Year (current year minus 1900)
'tm_wday' Day of the week (0-6; Sun = 0)
'tm_yday' Day of the year (0-365; Jan 1 = 0)
'tm_isdst' Non-zero if daylight saving time, otherwise zero
Returns: A pointer to the structure result. There is no error
return.
Notes: gmtime() and localtime() use a single statically
allocated structure to hold the result. Each call to
one of these routines destroys the result of the
previous call.
MS-DOS does not comprehend dates prior to its birth
in 1980. If 'time' represents a date prior to January
1, 1980, gmtime() returns 00:00:00, January 1, 1980.
-------------------------------- Example ---------------------------------
The following statements get the time stored as a long integer, store
it in a structure, convert the structure to a character string, and
print it out.
#include <time.h>
#include <stdio.h>
long elapstime;
struct tm *greentime;
main()
{
time(&elapstime);
greentime = gmtime(&elapstime);
printf("Greenwich time is %s\n",asctime(greentime));
}
See Also:
asctime()
ctime()
localtime()
time()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson